package com.franklin.java.api.linemarker;

import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 * @author Franklin
 * @since 2021/9/6 15:58
 */
public abstract class AbstractLineMarkerProvider<T extends PsiElement> extends LineMarkerProviderDescriptor {

    /**
     * 判断是否是需要标记的行<br>
     * @author Franklin
     * @since 2021/9/6 16:00
     * @param t:
     * @return boolean
     */
    protected abstract boolean isMarkerTarget(@NotNull PsiElement psiElement);

    @Override
    @NotNull
    public abstract Icon getIcon();

    @Override
    public abstract LineMarkerInfo<T> getLineMarkerInfo(@NotNull PsiElement psiElement);


    @Override
    public String getName() {
        return this.getClass().getName();
    }

    protected T getObject(PsiElement psiElement){
        if (!isMarkerTarget(psiElement)){
            return null;
        }
        return (T)psiElement;
    }
}
